package org.teststack.restAssured;

import java.util.HashMap;
import java.util.Map;

import static com.jayway.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.teststack.utils.ReadConf.getHost;
import static org.teststack.utils.ReadConf.readConf;

public class baidu {
    public static void main(String[] args) {
        String host = getHost();
        String url = host + "/api/v1/user/login";
        login(url);
    }

    public static void baidu(String url) {
        given().               //准备用rest-assured发起请求

                get(url).     //get请求
//                get("http://10.1.10.103:8080/api/v1/product/list").

                then().                            //请求后要准备什么
                statusCode(200).
                log().all();                      //打印所有日志"794666918@qq.com
    }

    public static void login(String url) {
        //定义多个参数，hashmap定义kv格式参数
//        Map<String, String> para = new HashMap<String, String>();
//        para.put("mail","794666918@qq.com");
//        para.put("pwd","123456");
        given().
                headers("Content-Type","application/json").
//                params(para).         //请求带参
                body("{\"mail\":\"794666918@qq.com\",\"pwd\":\"123456\"}\n" ).  //json请求
                when().
                post(url).
                then().
                statusCode(200).
                body("code",equalTo(0)).
                log().all();
    }
}
